package com.dq.domain.record;

import com.dq.domain.subscribe.Subscribe;
import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.org.Org;
import com.dq.domain.sys.user.user.StaffUser;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.domain.sys.user.user.WxUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/20 0020 12:41:13
 */
@Data
@Entity
@ApiModel("服务记录")
public class ServiceRecord extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("服务编号")
    protected String serviceNo;

    @ApiModelProperty("用户")
    @ManyToOne
    protected SysUser wxUser;

    @ApiModelProperty("门店")
    @ManyToOne
    protected Org sysDept;

    @ApiModelProperty("技师")
    @ManyToOne
    protected SysUser staffUser;

    @ApiModelProperty("服务开始时间")
    protected Long serviceBeginTime;

    @ApiModelProperty("服务结束时间")
    protected Long serviceEndTime;

    @ApiModelProperty("服务返金")
    protected BigDecimal serviceBackAmount;

    @ApiModelProperty("服务状态")
    protected ServiceStatus serviceStatus;

    @ApiModelProperty("预约")
    @ManyToOne
    protected Subscribe subscribe;

    @ApiModelProperty("项目名")
    protected String projectName;

    @ApiModelProperty("项目类型")
    protected String projectCategoryName;

    @ApiModelProperty("服务手工费")
    protected BigDecimal manualPrice;

    @ApiModelProperty("超时时间")
    protected Long timeoutTime;

    public enum ServiceStatus{
        inService("服务中"),
        endService("服务结束"),
        confirmed("待确认"),
        evaluate("待评价")
        ;
        public String name;
        ServiceStatus(String name) {
            this.name = name;
        }

    }


    @Data
    @ApiModel(value = "服务记录视图")
    public static class Vo implements VO {

    }

    @Data
    @ApiModel("用户服务记录")
    public static class WxUserServiceVO{

    }


    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();

        return vo;
    }

    @Data
    @ApiModel("用户服务记录列表")
    public static class UserServiceRecord{
        @ApiModelProperty("服务记录id")
        protected Long id;
        @ApiModelProperty("服务开始时间")
        protected String serviceBeginTime;
        @ApiModelProperty("技师")
        protected String staffUser;
        @ApiModelProperty("服务项目名称")
        protected List<String> projectName;
        @ApiModelProperty("预约次数")
        protected Long subscribeNum;
        @ApiModelProperty("服务次数")
        protected Long serviceNum;
        @ApiModelProperty("是否评价")
        protected Boolean isEvaluate;
        @ApiModelProperty("评价id")
        protected Long evaluateId;
    }

    public UserServiceRecord toUserServiceRecord(Boolean isEvaluate,List<String> projectName,Long evaluateId){
        UserServiceRecord vo = new UserServiceRecord();
        vo.id = this.id;
        vo.serviceBeginTime = fmt(this.serviceBeginTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        StaffUser staffUser = (StaffUser)this.staffUser;
        vo.staffUser = staffUser.getUserRealcName();
        vo.projectName = projectName;
        vo.isEvaluate = isEvaluate;
        vo.evaluateId = evaluateId;
        return vo;
    }

    @Data
    @ApiModel("门店用户服务记录视图")
    public static class OrgUserServiceRecordVo{
        @ApiModelProperty("id")
        protected Long id;
        @ApiModelProperty("技师真实姓名")
        protected String getUserRealcName;
        @ApiModelProperty("服务返金")
        protected BigDecimal serviceBackAmount;
        @ApiModelProperty("服务状态")
        protected String serviceStatus;
        @ApiModelProperty("服务状态")
        protected ServiceStatus serviceStatusEn;
        @ApiModelProperty("服务开始时间")
        protected String serviceBeginTime;
        @ApiModelProperty("服务结束时间")
        protected String serviceEndTime;
        @ApiModelProperty("服务项目名称")
        protected String projectName;
        @ApiModelProperty("顾客等级")
        protected String levelName;
        protected String customerName;
    }
    public OrgUserServiceRecordVo toOrgUserServiceRecordVo(){
        OrgUserServiceRecordVo orgUserServiceRecordVo = new OrgUserServiceRecordVo();
        orgUserServiceRecordVo.id = this.getId();
        StaffUser staffUser = (StaffUser)this.getStaffUser();
        orgUserServiceRecordVo.getUserRealcName = fmt(staffUser.getUserRealcName());
        orgUserServiceRecordVo.serviceBackAmount = fmt(this.getServiceBackAmount());
        orgUserServiceRecordVo.serviceStatus = fmt(this.getServiceStatus().name);
        orgUserServiceRecordVo.serviceStatusEn = this.serviceStatus;
        orgUserServiceRecordVo.serviceBeginTime = fmt(this.getServiceBeginTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS);
        orgUserServiceRecordVo.serviceEndTime = fmt(this.getServiceEndTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS);
        orgUserServiceRecordVo.projectName = fmt(this.getProjectName());
        WxUser wxUser = this.getWxUser() != null ? (WxUser) this.getWxUser():new WxUser();
        orgUserServiceRecordVo.levelName =  wxUser.getOrgCustomerLevel()!= null ? wxUser.getOrgCustomerLevel().getLevenName():"";
        orgUserServiceRecordVo.customerName = wxUser.getUserRealcName();
        return orgUserServiceRecordVo;
    }
    @Data
    @ApiModel("pc服务记录视图")
    public static class PcServiceRecord{
        @ApiModelProperty("服务记录id")
        protected Long id;
        @ApiModelProperty("服务编号")
        protected String serviceNo;
        @ApiModelProperty("项目名")
        protected String projectName;
        @ApiModelProperty("服务创建时间")
        protected String createTime;
        @ApiModelProperty("服务开始时间")
        protected String serviceBeginTime;
        @ApiModelProperty("服务结束时间")
        protected String serviceEndTime;

        @ApiModelProperty("门店名")
        protected String orgName;

        @ApiModelProperty("顾客ID")
        protected Long wxUserId;
        @ApiModelProperty("顾客编号")
        protected String wxUserCardNo;
        @ApiModelProperty("顾客名称")
        protected String wxUserUserRealName;
        @ApiModelProperty("员工工号")
        protected String cardNo;
        @ApiModelProperty("员工姓名")
        protected String userRealName;

        @ApiModelProperty("评价得分")
        protected Long averageNum;
        @ApiModelProperty("服务手工费")
        protected BigDecimal manualPrice;
    }

    public PcServiceRecord toPcServiceRecord(Long averageNum){
        PcServiceRecord vo = new PcServiceRecord();
        vo.id = this.getId();
        vo.serviceNo = fmt(this.getServiceNo());
        vo.projectName = fmt(this.getProjectName());

        vo.orgName = this.getSysDept().getSimpleName();

        vo.createTime = fmt(this.createTime,TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.serviceBeginTime = fmt(this.getServiceBeginTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.serviceEndTime = fmt(this.getServiceEndTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);

        vo.wxUserId = fmt(this.getWxUser().getId());
        vo.wxUserCardNo = fmt(this.getWxUser().getCardNo());
        vo.wxUserUserRealName = fmt(this.getWxUser().getUserRealcName());
        vo.cardNo = fmt(this.getStaffUser().getCardNo());
        vo.userRealName = fmt(this.getStaffUser().getUserRealcName());

        vo.averageNum = averageNum;
        vo.manualPrice = fmt(this.getManualPrice());

        return vo;
    }
}
